package com.lagou.dao.impl;

import com.lagou.dao.ArticleDao;
import com.lagou.domain.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author StarryHorizon
 * @create 2022-02-28 22:04
 */
@Repository //生成该类的实例存到IOC容器中
public class ArticleDaoImpl implements ArticleDao {

    //从Spring中获取到jdbcTemplate的实例，注入进来
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /*
        添加文章信息
     */
    @Override
    public void save(Article article) {
        String sql = "insert into t_article values(null, ?, ?)";
        jdbcTemplate.update(sql, article.getTitle(), article.getContext());
    }
}
